import sys
from PyQt5.QtWidgets import QWidget, QApplication, QFileDialog, QGridLayout, QMainWindow, QLCDNumber
from trainWindow import Ui_MainWindow
from train_process import preprocessing, train_process


class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)
        self.folder_1 = ""
        self.folder_2 = ""
        self.whitename = ""

    def chooseFolder1(self):
        self.folder_1 = QFileDialog.getExistingDirectory(self, "选择文件夹", "C:\\")
        self._folder.setText(self.folder_1)

    def chooseFolder2(self):
        self.folder_2 = QFileDialog.getExistingDirectory(self, "选择文件夹", "C:\\")
        self._folder_2.setText(self.folder_2)

    def choose_white(self):
        self.whitename, fileType = QFileDialog.getOpenFileName(None, "选取文件", "C:\\", "Text Files(*.txt)")
        self.white_file.setText(self.whitename)


    def train_data(self):
        self.X, self.Y = preprocessing(self.folder_1, self.folder_2, self.whitename)
        r = train_process(self.X, self.Y, self.test_ratio.value(), self.layers_num.value(), self.learning_rate.value(), self.ac_fun.currentText(), self.final_fun.currentText(), self.dropout.value(), self.neuron_num.value())
        self.lcdNumber.setSegmentStyle(QLCDNumber.Flat)
        self.lcdNumber.setDigitCount(6)
        self.lcdNumber.display(str(r[1])[:6])


if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = MainWindow()
    win.setWindowTitle("Train")
    win.show()
    sys.exit(app.exec_())